﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace BMManage
{
    public partial class FormMain : Form
    {
        public BMWebService.DataSetDB.USERSRow SystemUser = null;
        public FormMain()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            FormAddArea f = new FormAddArea();
            f.ShowDialog();
        }

        private void FormMain_Load(object sender, EventArgs e)
        {
            if (SystemUser.LOGINNAME.ToLower() == "admin")
            {
                button1.Visible = true;
                button2.Visible = true;
            }
            else
            {
                button1.Visible = false;
                button2.Visible = false;
            }
        }

        private void button3_Click(object sender, EventArgs e)
        {
            SaveFileDialog sfd = new SaveFileDialog();
            sfd.Filter = "*|*.csv";
            if (sfd.ShowDialog() == DialogResult.OK)
            {
                BaseExportCSV.ExportCSV(this.dataGridView1, sfd.FileName);
            }

        }

        private void button4_Click(object sender, EventArgs e)
        {
            BMWebService.BMWebService serv = new BMWebService.BMWebService();
            if (SystemUser.LOGINNAME.Trim() == "admin")
            {
                //this.pERSIONSBindingSource.DataSource = serv.GetBaoMingData("");
                this.dataGridView1.DataSource = serv.GetBaoMingData("").DefaultView;
            }
            else
            {
                // this.pERSIONSBindingSource.DataSource = serv.GetBaoMingData(SystemUser.AREA);

                this.dataGridView1.DataSource = serv.GetBaoMingData(SystemUser.AREA).DefaultView;
            }

        }

        private void button2_Click(object sender, EventArgs e)
        {
            FormUser frm = new FormUser();
            frm.ShowDialog();
        }

        private void button5_Click(object sender, EventArgs e)
        {
            BMWebService.BMWebService serv = new BMWebService.BMWebService();
            int val = 0;
            int.TryParse(dataGridView1.CurrentRow.Cells[0].Value.ToString(), out val);
            this.dataGridView1.DataSource = serv.UpdateStatus(val).DefaultView;
        }

        private void button6_Click(object sender, EventArgs e)
        {
            BMWebService.BMWebService serv = new BMWebService.BMWebService();
            int val = 0;
            int.TryParse(dataGridView1.CurrentRow.Cells[0].Value.ToString(), out val);
            this.dataGridView1.DataSource = serv.DeleteRow(val).DefaultView;
        }
    }
}
